import { Jifen } from './jifenList-model.js';
import { Center } from './center-model.js';
import { Evaluate } from '../evaluate/evaluate-model.js';
var center = new Center();
var jifen = new Jifen();
var evaluate = new Evaluate();
Page({
  data: {
    loadingHidden: false,
  },
  onLoad: function (options) {
    this._loadData();
  },
  _loadData: function () {
    jifen._getJifenScore(res=>{
      this.setData({
        score:res.item.score,
        rule: res.info,
        loadingHidden: true
      })
    })
    center.getAccountsList({'change_type':1}, res=>{
      var listData = res.items; 
      this.setData({
        listData: listData
      })
      for (var i = 0; i < listData.length; i++) {
        var date = evaluate.toDate(listData[i].created_at);
        var change_score = '';
        if (listData[i].change_score>0){
          change_score = '+' + listData[i].change_score;
        }else{
          change_score = listData[i].change_score;
        }
        var upscore = 'listData[' + i + '].change_score'
        var time = 'listData[' + i + '].created_at';
        this.setData({
          [time]: date,
          [upscore]: change_score
        })
      }
    })
  },

  toGoodsList:function(){
    wx.navigateTo({
      url: '../product/list',
    })
  },
  toScore:function(){
    wx.showToast({
      title: '开发中~',
      icon: 'none',
      duration: 2000
    })
  },

  onReachBottom: function () {

  },


})